<?php

namespace app\admin\model;

use think\Model;

/**
 * 提现记录
 * Class Withdraw
 * @package app\admin\model
 */
class Withdraw extends Model
{
    /**
     * 提现记录
     * @param $where
     * @param $page
     * @param $pagesize
     * @return array
     */
    public static function getWithdrawList($where, $page, $pagesize)
    {
        $data = self::alias('w')
            ->join('users u', 'u.id = w.links_id', 'left')
            ->where($where)
            ->field('w.*,u.nickname,u.headimg')
            ->order('create_time', 'desc')
            ->page($page, $pagesize)
            ->select();

        return $data ? $data->toArray() : [];
    }

    /**
     * 统计提现记录
     * @param $where
     * @return int
     */
    public static function countWithdrawList($where)
    {
        return self::alias('w')
            ->join('users u', 'u.id = w.links_id', 'left')
            ->where($where)
            ->count();
    }

    /**
     * 指定提现记录
     * @param $where
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function findWithdraw($where)
    {
        $info = self::where($where)->find();

        return $info ? $info->toArray() : [];
    }

    /**
     * 更新提现记录
     * @param $where
     * @param $data
     * @return Withdraw
     */
    public static function updateWithdraw($where, $data)
    {
        return self::update($data, $where);
    }
}